var vm=new Vue({
    el:"#app",

    data:{
        list:[
            {name:'秋刀鱼',price:22,pic:"pic.png",count:1},
            {name:'大龙虾',price:42,pic:"pic.png",count:1},
            {name:'皮皮虾',price:20,pic:"pic.png",count:1}
        ]
    },

    methods:{
        add(item){
            if( item.count<5 ) item.count++;   
        },
        sub(item){
            if( item.count > 1 )item.count--;
        },
        clean(){
            this.list=[]
        }
    },
    computed:{  //负责定义计算属性
        totalCount(){
            var sum=0;
            this.list.forEach(item => {
                sum+=item.count;   
            });
            return sum;
        },
        totalPrice(){
            var sum=0;
            this.list.forEach(item=>{
                sum+=item.count*item.price
            })
            return sum;
        }

    }  
})